package com.anniljing.kotlionlearn.Basic.coroutine

import kotlinx.coroutines.*

fun main() {
    testSync()
}

/**
 * 测试job的生命周期
 */
fun testJobLife(){
    runBlocking {
        val job=launch(start = CoroutineStart.LAZY){
            logX("Coroutine start!")
            delay(1000L)
        }
        job.log()
        job.start()
        job.log()
        delay(1000L)
        job.log()
        job.invokeOnCompletion {
            job.log()
        }
        job.join()
    }
}

fun testSync(){
    runBlocking {
        val parentJob:Job
        var job1:Job?=null
        var job2:Job?=null
        var job3:Job?=null

        parentJob=launch {
            job1=launch {
//                delay(1000L)
                println("job1 start")
            }
            job2=launch {
//                delay(3000L)
                println("job2 start")
            }
            job3=launch {
//                delay(5000L)
                println("job3 start")
            }
        }
//        delay(500L)
        parentJob.join()
    }
}